<include file="Public/head"/>
<style type="text/css">
    .inputys{background-color:rgba(255,255,255,0); height:50px;outline: none; border:0px; color:#fff;width:100%;}
    .choose{
        padding: .8rem .2rem;
        font-size: .3rem;
        /* font-weight: 700; */
        /*border-bottom: 1px solid #e6e6e6;*/
    }
    .copy_btn {
        margin-top: 4rem;
        width: 100%;
        background-color: rgba(18,27,56,0.9);
        text-align: center;
        line-height: 3rem;
        border-radius: .05rem;
        /*color: #808bab;*/
        color: #ffff;
        height: 3rem;
    }
</style>

<body style="padding-top: 38px">
<div class="title1" >
    <div class=" col-xs-4" style="text-align:left">
        <a href="{:U('Finance/wallet')}" style="color:#333;">
            <span class="glyphicon glyphicon-menu-left" aria-hidden="true" ></span>
        </a>
    </div>
    <div class=" col-xs-4">{:L('_CB_')}</div>
    <div class=" col-xs-4">


    </div>
</div>

<div class="container" style=" padding-top:40px;">

    <if condition="$isAddress eq 1">

        <div class="copy_btn"  id="addr">点击生成充币地址</div>

        <else/>

        <div style=" color:#475377; margin-top:15px;">
        <div class="choose">
            <select class="form-control" style="margin-top: 5px;background-color: #F1F3F4;border: 1px solid #475377;" id="charge">
                <!--<select name="" id="charge">-->
                <!--<option value="1">BTC</option>-->
                <!--<option value="2">ASSET</option>-->
                <option value="4">ASSET</option>
                <option value="5">EASY</option>
                <option value="3">USDT</option>

                <option value="6">ETH</option>
                <option value="7">BTC</option>
                <option value="8">EOS</option>
            </select>
        </div>

        <img src="__IMG__/tt.png" width="18" height="18"/>
        <!--{:L('_TS1_')}-->
        请不要向上述的地址充值任何非<span id="coin" style="color: red;">ASSET</span>资产，否则资产将无法找回。
    </div>

    <!--     <div style=" color:#475377; margin-top:15px;">
        <img src="__IMG__/tt.png" width="18" height="18"/>

        </div>

        <div style=" color:#475377; margin-top:15px;">
        <img src="__IMG__/tt.png" width="18" height="18"/>

        </div>   -->



        <!--<div id="code" style="position: relative; left: 83px;background-color: #FFF;width: 180px;margin-top: 15px;">-->
        <div id="code" style="position: relative; left: 95px;background-color: #FFF;width: 43.5%;margin-top: 15px;">

        </div>

    <div class="row-fluid"  style="margin:0 15px 0 15px;">
        <!--<div id="code"></div>-->
        <!--<input type="text" id="copyVal" readonly value="{$coinAddress}">-->


        <!--<input type="text" id="copyVal" readonly value="{$coinAddress}">-->
        <!--<div class="copy_btn" style="cursor: pointer" onclick="" data-clipboard-target="#copyVal">点击复制地址</div>-->


        <!--<div class="copyword"></div>-->
        <!--<textarea style="width: 100%;color:#d1dcff;height: 0;line-height: 20px;background: #09102c;border-width: 0;opacity: 0" readonly="readonly" id="biao1">0x078AA8773566367f22f74A3E887e114CA6529671</textarea>-->
        <!--<textarea style="width: 100%;color:#d1dcff;height: 0;line-height: 20px;background: #09102c;border-width: 0;opacity: 0" readonly="readonly" id="biao1">{$coinAddress}</textarea>-->
        <!--<textarea style="width: 100%;color:#d1dcff;height: 0;line-height: 20px;background: #09102c;border-width: 0;opacity: 0" readonly="readonly" id="biao1">{$coinAddress}</textarea>-->
        <textarea style="width: 100%;color:#333;line-height: 20px;background: #F1F3F4;border-width: 0;" readonly="readonly" id="biao1">{$coinAddress}</textarea>
        <!--<input type="text" id="biao1" readonly value="{$coinAddress}">-->
        <div onClick="copyUrl2()" style="color:#2cd0da;height:25px;line-height: 25px;text-align: center;"> {:L('_FZDZ_')}</div>
        <!--            <table width="103%" border="1" cellspacing="0" cellpadding="0" style=" margin-top:15px; border:1px solid #121b38; height:40px; text-align:center; " >
                       <tr>
                           <td>

                           </td>
                       </tr>
                       <tr>
                           <td style="color:#2cd0da;height:25px;line-height: 25px;" onClick="copyUrl2()">点击复制地址</td>
                       </tr>
                   </table> -->
    </div>

    </if>

    <script>
        $(function(){
            // $(".copyword").text($("#biao1").text())
            $(".copyword").text($("#biao1").text())
        })
    </script>
    <style>
        .copyword{
            margin-top: 15px;
            width: 100%;
            color: #d1dcff;
            line-height: 20px;
            background: #09102c;
            border-width: 0;
            text-align: center;
            word-wrap: break-word;
        }
    </style>



    <!--<div class="row-fluid qk" >-->

        <!--<div style=" height:50px;">-->
            <!--<div class="col-xs-4 t3" style=" float:left; height:50px; line-height:50px; padding-left:15px; color:#808bab;">{:L('_CZDZ_')}</div>-->
            <!--<div class="col-xs-8" style=" float:left; height:50px; line-height:50px;">-->
                <!--<input type="text" id="address" placeholder="{:L('_SRCZDZ_')}" class="inputys" >-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="line1"></div>-->

        <!--<div style=" height:50px;">-->
            <!--<div class="col-xs-4 t3" style=" float:left; height:50px; line-height:50px; padding-left:15px;">{:L('_GBCSL_')}</div>-->
            <!--<div class="col-xs-8" style=" float:left; height:50px; line-height:50px;">-->
                <!--<input type="text" id="amount" placeholder="{:L('_SRSL1_')}" class="inputys" >-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="line1"></div>-->
    <!--</div>-->

    <!--<div style=" margin-top:20px;">-->
        <!--<button id="btn-1" style="width: 49.2%;">{:L('_TJSQ_')}</button>-->
        <!--<a href="{:U('Finance/detail')}" style="color: #FFF;text-decoration:none;">-->
            <!--<button class="btn-2" type="button" style="width: 49.5%;">{:L('_CKJL_')}</button>-->
        <!--</a>-->
    <!--</div>-->



</div>
</body>
</html>
<!-- 获取地址 -->
<script type="text/javascript">

    $('#charge').change(function(){
        $("#code div").remove();
        var coinname = $("#charge").val();
        // alert(coinname);return false;
        //传输数据
        $.ajax({
            type : 'POST',
            url:"{:U('Finance/coinName')}",
            dataType : 'json',
            data:{
                coinname:coinname,
            },
            success : function(data){

                if(data.code == 1){
                    alert(data.msg);
                }else
                {
                    $("#copyVal").val(data.data);

                    $("#coin").text(data.msg);

                    $('#code').qrcode({
                        render:'table',
                        text:data.data,
                        size: "150"

                    });
                }
            }
        })
    });
</script>

<!-- 引入js -->
<script type="text/javascript" src="__JS__/web3.1.js"></script>
<script src="__JS__/jquery.qrcode.min.js"></script>
<!--<script src="https://cdn.bootcss.com/clipboard.js/2.0.0/clipboard.min.js"></script>-->
<!-- 生成钱包地址 -->
<script type="text/javascript">

    if (typeof web3 !== 'undefined') {
        web3 = new Web3(web3.currentProvider);
    }
    else {
        // web3 = new Web3('https://mainnet.infura.io/JLEYzEEavNnSni91CvPF');
        // infura申请的地址
        web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/v3/96e3bf3bd1164bc4a5d8d9bb3dca6d3c"));
    }

    $('#addr').click(function(){
        //生成BTC地址
        //传输数据
        // $.ajax({
        //
        //     type : 'POST',
        //     url:"{:U('Finance/btcAddress')}",
        //     dataType : 'json',
        //     data:{
        //         coinname:'btc',
        //     },
        //     success : function(data){
        //
        //         if(data.code == 1){
        //             alert(data.msg);
        //             setTimeout(function(){ window.location.reload(); }, 1000);
        //         }else
        //         {
        //             alert(data.msg);
        //             setTimeout(function(){ window.location.reload(); }, 1000);
        //             //window.location.reload();
        //         }
        //     }
        // })

        //生成ETH地址
        function RndNum(n){
            var rnd="";
            for(var i=0;i<n;i++)
                rnd+=Math.floor(Math.random()*10);
            return rnd;
        }

        var password = RndNum(8);
        var account = web3.eth.accounts.create(password);
        var key = account.privateKey;
        var address = account.address;

        //传输数据
        $.ajax({
            type : 'POST',
            url:"{:U('Finance/ethAddress')}",
            dataType : 'json',
            data:{
                address:address,
                key:key
            },
            success : function(data){

                if(data.code == 1){
                    // alert(data.msg);
                    // layer.msg(data.message,{time:1000});
                    layer.msg(data.msg);
                    setTimeout(function(){ window.location.reload(); }, 1000);
                }else
                {
                    layer.msg(data.msg);
                    setTimeout(function(){ window.location.reload(); }, 1000);
                }
            }
        })
    });
</script>

<script type="text/javascript">

    // $('#code').qrcode({
    //     render: "table", //table方式
    //     size:180,
    //     text: "0x078AA8773566367f22f74A3E887e114CA6529671" //任意內容
    // });
    $('#code').qrcode({
        render:'table',
        text:"{$coinAddress}",
        size: "150"

    });
    // var copyBtn = new ClipboardJS('.copy_btn');
    // copyBtn.on("success",function(e){
    //     alert('复制成功');
    //     e.clearSelection();
    // });
    // copyBtn.on("error",function(e){
    //     //复制失败；
    //     alert('复制失败');
    // });
    // function copyUrl2()
    // {
    //     var Url2=document.getElementById("biao1");
    //     Url2.select(); // 選擇對象
    //     document.execCommand("Copy"); // 執行瀏覽器複製命令
    //     layer.msg("{:L('_FZCG_')}",{time:1000});
    // }
    // 思路：要想复制到剪贴板，必须先选中这段文字。
    function copyUrl2(){
        var NumClip=document.getElementById("biao1");
        var NValue=NumClip.value;
        var valueLength = NValue.length;
        selectText(NumClip, 0, valueLength);
        if(document.execCommand('copy', false, null)){
            document.execCommand('copy', false, null)// 执行浏览器复制命令
            layer.msg("{:L('_FZCG_')}",{time:1000});
            // console.log("已复制,赶紧分享给朋友吧");
        }else{
            layer.msg("不兼容",{time:1000});
            // console.log("不兼容");
        }

    }

    // input自带的select()方法在苹果端无法进行选择，所以需要自己去写一个类似的方法
    // 选择文本。createTextRange(setSelectionRange)是input方法
    function selectText(textbox, startIndex, stopIndex) {
        if(textbox.createTextRange){
            var range = textbox.createTextRange();
            range.collapse(true);
            range.moveStart('character', startIndex);//起始光标
            range.moveEnd('character', stopIndex - startIndex);//结束光标
            range.select();//不兼容苹果
        }else{
            textbox.setSelectionRange(startIndex, stopIndex);
            textbox.focus();
        }
    }


    $("#btn-1").click(function(){

        var address = $("#address").val();
        var amount = $("#amount").val();

        if(address == '' || amount == '')
        {
            layer.msg("{:L('_CBXXBWZ_')}",{time:1000});
            return false;
        }

        if(parseFloat(amount) <= 0)
        {
            layer.msg("{:L('_CBSL0_')}",{time:1000});
            return false;
        }

        if(parseFloat(amount) < 100)
        {
            layer.msg("{:L('_CBSL100_')}",{time:1000});
            return false;
        }

        layer.confirm("{:L('_QRCB_')}", {
            btn: ["{:L('_SHI_')}","{:L('_FOU_')}"] //按钮
        }, function(){


            $.ajax({
                type: 'POST',
                url: "{:U('Finance/charge')}",
                dataType: 'json',
                data: {
                    address:address,
                    amount:amount
                },
                success: function(data){
                    if(data.code>0){
                        layer.msg(data.message,{time:1000});

                        window.location.href="{:U('Finance/charge')}";
                    }
                    else{
                        layer.msg(data.message,{time:1000});
                    }
                }
            })


        }, function(){

        });

    });

</script>